﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FisheryPlatform.Bussiness.LoginCookie;
using FisheryPlatform.SiteConfig;
using FisheryPlatform.Bussiness.FileStore;
using FisheryPlatform.SiteConfig.FileStore;
using System.IO;
using FisheryPlatform.Bussiness.Passport;

namespace FisheryPlatform.Web.Admin
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //UploadFileEntity fileInfo = new UploadFileEntity("44444", "a.html", File.ReadAllBytes(@"E:\资料\数据库\赋权限.txt"));
            //fileInfo.UploadDate = DateTime.Now;
            //ProductStaticHtmlUploadProvider fileUpload = new ProductStaticHtmlUploadProvider(fileInfo);
            //fileUpload.Save();
            //var html = fileInfo.PublishUrlPath;
            //var content = ProductStaticHtmlUploadProvider.GetFileContent(fileInfo.UploadDate, fileInfo.Id);

            if (IsPostBack)
            {
                #region
                if (string.IsNullOrEmpty(txt_LoginName.Value) || string.IsNullOrEmpty(txt_Password.Value) || string.IsNullOrEmpty(txt_Code.Value))
                {
                    lbl_Tips.InnerHtml = "登录名、密码、验证码必填";
                }
                else
                {
                    if (ValidateCodeManager.Validate(txt_Code.Value) == false)
                    {
                        lbl_Tips.InnerHtml = "验证码输入错误";
                    }
                    else
                    {
                        if (LoginCookieManager.SignIn(txt_LoginName.Value, txt_Password.Value) == LoginResultEnum.Success)
                        {
                            if (string.IsNullOrEmpty(Request.QueryString["ReturnUrl"]) == false)
                            {
                                Response.Redirect(Request.QueryString["ReturnUrl"], false);
                            }
                            else
                            {
                                Response.Redirect("Index.aspx", false);
                            }
                        }
                        else
                        {
                            lbl_Tips.InnerHtml = "登录名或者密码错误";
                        }
                    }
                }
                #endregion
            }
        }
    }
}